﻿
using System.Linq;
using System;
using System.Web.Security;
using Web;
using System.Security.Cryptography;

namespace Web.Service
{
    public class Service
    {
        private DataModelContainer db = new DataModelContainer();

        public User GetUser(string name)
        {
            User u = db.User.Single(r => r.email.Equals(name));
            return u;
        }

        public bool ValidateUser(string username, string password)
        {
            Guid.NewGuid().ToString();
            //Service.CreatePasswordHash(password, dbuser.salt))
            User dbuser = GetUser(username);
            if (dbuser != null && dbuser.password.Equals(password))
            {
                return true;
                
            }
            return false;
        }

        public static string CreatePasswordHash(string pwd, string salt)
        {
            string saltAndPwd = String.Concat(pwd, salt);
            string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(
                    saltAndPwd, "sha1");
            return hashedPwd;
        }



    }
}